﻿<UserControl x:Class="ITG.Designer.DesignerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:des="clr-namespace:ITG.Designer"
             xmlns:drag="clr-namespace:ITG.DragAndDrop"
             xmlns:itg="clr-namespace:ITG"
             mc:Ignorable="d"
             d:DesignHeight="200" d:DesignWidth="200">

    <ScrollViewer Name="DesignerScrollViewer"
                  Background="Transparent"
                  HorizontalScrollBarVisibility="Auto"
                  VerticalScrollBarVisibility="Auto">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <des:PixelRuler Grid.Row="0" Grid.Column="1" AutoSize="True" SmallStep="10" Step="50" Marks="Down" />

            <des:PixelRuler Grid.Row="1" Grid.Column="0" AutoSize="True" SmallStep="10" Step="50">
                <des:PixelRuler.LayoutTransform>
                    <RotateTransform Angle="90" />
                </des:PixelRuler.LayoutTransform>
            </des:PixelRuler>

                <ItemsControl Grid.Row="1" Grid.Column="1" ItemsSource="{Binding ActiveTab.Items}">
                    <ItemsControl.Resources>
                        <!-- Style for DesignerItems in general, governing basic dimensions, resizers, etc
                             This must remain here - it gives a different DataContext (DesignerVM) if elsewhere -->
                        <Style TargetType="{x:Type ContentPresenter}">
                            <Setter Property="Canvas.Top" Value="{Binding Top}" />
                            <Setter Property="Canvas.Left" Value="{Binding Left}" />
                            <Setter Property="des:SelectionAttachedProperties.EnabledForSelection" Value="True" />
                            <Setter Property="Width" Value="{Binding Width}" />
                            <Setter Property="Height" Value="{Binding Height}" />
                            <Setter Property="SnapsToDevicePixels" Value="True" />
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Grid x:Name="selectedGrid" >
                                            <!-- Context Menu when an item is right-clicked on -->
                                            <Grid.ContextMenu>
                                                <ContextMenu>
                                                    <MenuItem Header="Delete" DataContext="{Binding Path=ParentTab}" Command="{Binding RemoveSelectedItemsCommand}" />
                                                </ContextMenu>
                                            </Grid.ContextMenu>

                                            <!-- Enables moving -->
                                            <drag:DragThumb x:Name="PART_DragThumb" Cursor="SizeAll" />

                                            <!-- The actual control/designer item -->
                                            <ContentPresenter x:Name="PART_ContentPresenter"
                                                                HorizontalAlignment="Stretch"
                                                                VerticalAlignment="Stretch"
                                                                Content="{TemplateBinding Content}" />
                                            <!-- Enables resizing -->
                                            <drag:ResizeThumb Name="RESIZE_Top"
                                                       Height="2" Cursor="SizeNS"
                                                       VerticalAlignment="Top" HorizontalAlignment="Stretch" />
                                            <drag:ResizeThumb Name="RESIZE_Bottom"
                                                       Height="2" Cursor="SizeNS"
                                                       VerticalAlignment="Bottom" HorizontalAlignment="Stretch" />
                                            <drag:ResizeThumb Name="RESIZE_Left"
                                                       Width="2" Cursor="SizeWE"
                                                       VerticalAlignment="Stretch" HorizontalAlignment="Left" />
                                            <drag:ResizeThumb Name="RESIZE_Right"
                                                       Width="2" Cursor="SizeWE"
                                                       VerticalAlignment="Stretch" HorizontalAlignment="Right" />
                                            <drag:ResizeThumb Name="RESIZE_TopLeft"
                                                       Cursor="SizeNWSE"
                                                       Width="3" Height="3"
                                                       VerticalAlignment="Top" HorizontalAlignment="Left" />
                                            <drag:ResizeThumb Name="RESIZE_TopRight"
                                                       Cursor="SizeNESW"
                                                       Width="3" Height="3"
                                                       VerticalAlignment="Top" HorizontalAlignment="Right" />
                                            <drag:ResizeThumb Name="RESIZE_BottomLeft"
                                                       Cursor="SizeNESW"
                                                       Width="3" Height="3"
                                                       VerticalAlignment="Bottom" HorizontalAlignment="Left" />
                                            <drag:ResizeThumb Name="RESIZE_BottomRight"
                                                       Cursor="SizeNWSE"
                                                       Width="3" Height="3"
                                                       VerticalAlignment="Bottom" HorizontalAlignment="Right" />

                                            <!-- Highlights the control when selected -->
                                            <Rectangle x:Name="PART_InnerSelectionBorder"
                                                       StrokeThickness="3"
                                                       Stroke="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                                       Fill="Transparent"
                                                       IsHitTestVisible="False"
                                                       Visibility="Hidden" />

                                        </Grid>

                                        <DataTemplate.Triggers>
                                            <!-- Show the inner selection border when selected -->
                                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                <Setter TargetName="PART_InnerSelectionBorder" Property="Visibility" Value="Visible" />
                                            </DataTrigger>
                                        </DataTemplate.Triggers>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ItemsControl.Resources>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <des:DesignerCanvas HorizontalAlignment="Left" VerticalAlignment="Top"
                                                MinWidth="{Binding Path=MinWidth, Mode=OneWay}" MinHeight="{Binding Path=MinHeight, Mode=OneWay}"
                                                Width="{Binding Path=Width}" Height="{Binding Path=Height}"
                                                Background="LightGray"
                                                AllowDrop="True">
                            </des:DesignerCanvas>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>

           
        </Grid>
    </ScrollViewer>
</UserControl>